﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;
using MyGeneration.dOOdads;

namespace MobileShop
{
    public partial class Contact :BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (View_Customers.GetCurrentUser() != null)
                {
                    txtName.Text = View_Customers.GetCurrentUser().s_CustomerName;
                    txtAddress.Text = View_Customers.GetCurrentUser().s_Address;
                    txtEmail.Text = View_Customers.GetCurrentUser().s_Email;
                }
                PageMap = string.Format("Contact[{0}]", this.ResolveUrl("~/Contact.aspx"));
            }
        }

        protected void btnSubmit_OnClick(object sender, EventArgs e)
        {
            lblError.Text = "";
            lblNote.Visible = false;
            ccJoin.ValidateCaptcha(txtCode.Text);
            if (!ccJoin.UserValidated)
            {
                txtCode.Text = "";
                lblError.Text = "Invaid validation code! Please type again.";
                return;
            }
            try
            {
                CustomerRequests req = CustomerRequests.AddNewRequest(txtName.Text, txtEmail.Text, txtAddress.Text, txtSubject.Text, txtContent.Text.Replace("\n", "<br/>"));
                lblNote.Visible = true;
                return;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("Contact.aspx.cs", "btnSubmit_OnClick", ex.StackTrace);
                lblError.Text = "Error in sending message. Please contact website administrator.";
            }
        }
    }
}